/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ServerGUI.java
 *
 * Created on Aug 4, 2011, 3:52:22 AM
 */

package Graphics;

import GameEngine.GameServer;
import GameEngine.Level;
import java.awt.CardLayout;
import javax.swing.DefaultListModel;

/**
 *
 * @author crdunwel
 */
public class ServerGUI extends javax.swing.JFrame
{
    public GameServer serverGame;
    private DefaultListModel model;
    public boolean gameover;
    public boolean serverRunning;
    public String xpath;
    public int port;
    public byte levelbyte;
    public ServerGUI servergui;

    /** Creates new form ServerGUI */
    public ServerGUI(Level lvl, int portNum, byte level)
    {
        model = new DefaultListModel();
        port = portNum;
        levelbyte = level;
        serverGame = new GameEngine.GameServer(lvl, port, levelbyte, this);
        serverGame.setLog(model);
        // checks if ServerSocket successfully initiated
        if (serverGame.getServerSocket() != null)
        {
            serverRunning = true;
            setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            setVisible(true);
            serverGame.start();
            initComponents();
            replayButton.setVisible(false);
        }
        // otherwise destroy frame 
        else
        {
            serverRunning = false;
            dispose();
        }


    }

    public void setGameOver(boolean state)
    {
        gameover = state;
        if (gameover = true)
        {
            replayButton.setVisible(true);
        }
    }

    public void startServerThread()
    {
        serverGame.start();
    }

    public void exitWindow()
    {
        this.dispose();
    }

    public boolean isServerRunning()
    {
        return serverRunning;
    }
   


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        replayButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(800, 600));
        setResizable(false);

        jList1.setModel(model);
        jScrollPane1.setViewportView(jList1);

        replayButton.setText("Replay?");
        replayButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                replayButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 824, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(313, 313, 313)
                        .addComponent(replayButton, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(72, 72, 72)
                .addComponent(replayButton, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(86, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void replayButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_replayButtonActionPerformed

        /*

        if (gameover)
        {
            serverGame = new GameEngine.GameServer(xpath, port, levelbyte, this);
            serverGame.setLog(model);
            serverGame.start();
        }*/
    }//GEN-LAST:event_replayButtonActionPerformed



    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JList jList1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton replayButton;
    // End of variables declaration//GEN-END:variables

}
